package cn.gson.springmvc.model.service;

import cn.gson.springmvc.model.dao.ZuserDao;
import cn.gson.springmvc.model.mappers.ZuserMappers;
import cn.gson.springmvc.model.pojos.User;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ZuserService {
    @Autowired
    ZuserMappers zuserMappers;

    @Autowired
    ZuserDao zuserDao;
    public JSONArray selectUser(){
        return zuserMappers.selectUser();
    }

    @Transactional(value ="transactionManager" ,rollbackFor = Exception.class)
    public void updateStatus(int userId){
        User user = zuserDao.findById(userId).get();
        user.setUserIsshow(0);
        if(user.getUserIsshow()==1){
            user.setUserIsshow(0);
        }else{
            user.setUserIsshow(1);
        }

    }
    public JSONObject selectusers(int userId){
        return zuserMappers.selectusers(userId);
    }

    @Transactional(value ="transactionManager" ,rollbackFor = Exception.class)
    public void updateresetpwd(int userId){
        User user=zuserDao.findById(userId).get();
        user.setUserPwd("123456");
        zuserDao.save(user);
        /*if(user.getUserPwd()!="123456"){
            user.setUserPwd("123456");
        }else {
            user.setUserPwd("123456");
        }*/
    }

}
